package com.smedi.ismedi.inmail.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.authority.starter.util.AuthorityUtil;
import com.smedi.ismedi.authority.starter.util.VerifyHelper;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Attachment;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLog;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Person;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Project;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.announcement.Announcement;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.announcement.Receiver;
import com.smedi.ismedi.inmail.core.domain.dto.AnnouncementQuery;
import com.smedi.ismedi.inmail.core.domain.dto.AttachmentQuery;
import com.smedi.ismedi.inmail.core.domain.dto.LoginLogQuery;
import com.smedi.ismedi.inmail.core.domain.dto.PersonQuery;
import com.smedi.ismedi.inmail.core.domain.repository.AnnouncementRepository;
import com.smedi.ismedi.inmail.core.domain.repository.AttachmentRepository;
import com.smedi.ismedi.inmail.core.domain.repository.LoginLogRepository;
import com.smedi.ismedi.inmail.core.domain.repository.PersonRepository;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.AnnouncementAttachmentRelationshipEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.AnnouncementEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.AnnouncementReceiverRelationshipEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.LoginLogEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.AnnouncementAttachmentRelationshipMapper;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.AnnouncementMapper;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.AnnouncementReceiverRelationshipMapper;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.LoginLogMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.*;
import java.util.stream.Collectors;

import static com.smedi.ismedi.inmail.core.infrastructure.constant.AnnouncementStatusEnum.C_PUBLISHED;
import static com.smedi.ismedi.inmail.core.infrastructure.constant.ConstantField.COMPANY_MANAGEMENT_ORGANIZATION;
import static com.smedi.ismedi.inmail.core.infrastructure.constant.ConstantField.PROJECT_MANAGEMENT_ORGANIZATION;
import static com.smedi.ismedi.inmail.core.infrastructure.constant.RecordSourceFromTypeEnum.*;

/**
 * 主体院关系实现类
 *
 * @author niuyanling
 * @date 2021/08/05
 */
@Repository
@AllArgsConstructor
public class LoginLogRepositoryImpl implements LoginLogRepository {
    private final AdapterConverter adapterConverter;

    private final LoginLogMapper loginLogMapper;

    private final VerifyHelper verifyHelper;

    @Override
    public Long create(LoginLog loginLog) {
        LoginLogEntity loginLogEntity = adapterConverter.loginLogToLoginLogEntity(loginLog);
        loginLogMapper.insert(loginLogEntity);
        return loginLogEntity.getId();
    }

    @Override
    public void update(LoginLog loginLog) {
        loginLogMapper.updateById(adapterConverter.loginLogToLoginLogEntity(loginLog));
    }
}